package main

import (
	"fmt"
	"time"
)

func main() {
	cycleTimer()
}

func OneTimeTimer() {
	ch := make(chan string)

	go func() {
		time.Sleep(3 * time.Second)
		ch <- "response"
	}()

	select {
	case res := <-ch:
		fmt.Println("Received:", res)
	case <-time.After(2 * time.Second):
		fmt.Println("Timeout!")
	}
}

func cycleTimer() {
	ticker := time.NewTicker(1 * time.Second)

	go func() {
		for t := range ticker.C {
			fmt.Println("Tick at", t)
		}
	}()

	time.Sleep(5 * time.Second) // 主 goroutine 等待一段时间
	ticker.Stop()
	fmt.Println("Ticker stopped")
}
